package ar.edu.untref.edd3.model;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import ar.edu.untref.edd3.model.DAO.PersonaDAO;
import ar.edu.untref.edd3.persistence.HibernateUtil;

public class PersonaDaoHibernateImp implements PersonaDAO{

	@Override
	public void save(Persona persona) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		session.save(persona);
		
		session.getTransaction().commit();
	}

	public List<Persona> findByNombre(String nombre) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		Criteria c = session.createCriteria(Persona.class);
		c.add(Restrictions.eq("nombre", nombre));
		
		List<Persona> personas = (List<Persona>)c.list();
		
		session.getTransaction().commit();
		
		return personas;
	}
	
}
